<%@ page contentType="text/html;charset=utf-8"%>
<%@ taglib prefix="ww" uri="/struts-tags"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>经济主体档案管理系统</title>
    <link href="${ctx}/css/reset.css" rel="stylesheet">
    <link href="${ctx}/css/layui.css" rel="stylesheet">
    <link href="${ctx}/css/main.css?v=2" rel="stylesheet">
  <body>           
  <div class="content">
    <img src="${ctx}/img/login/logo.png" class="logo"/>
    <img src="${ctx}/img/login/title.png" class="title" />
    <div id="loginArea"  class="box">
      <ul class="layui-nav" lay-filter="">
        <li id="liCx" class="layui-nav-item layui-this" data-id="Cx"><a href="javascript:;">查询</a></li>
        <li id="liJd"  class="layui-nav-item" data-id="Jd"><a href="javascript:;">建档</a></li>
        <li id="liGl"  class="layui-nav-item" data-id="Gl"><a href="javascript:;">管理</a></li>
      </ul>
      <object type="application/cert-reader"  id="CertCtl" width=0 height=0> </object>
      <div id="boxCx" class="dialog active">
          <form id="cxForm" name="form" method="post" action="${ctx}/login.action?action=login" >

              <div class="text">
                <div class="textbox">
                  <i class="name"><img src="${ctx}/img/login/icon1.png"/></i>
                  <input id="cxUsername" type="text" name="userName" placeholder="请输入用户名" tabindex="0">
                  <button class="clock" onClick="readCert();" type="button">读卡</button>
                </div>
                <div class="textbox">
                  <i class="psw"><img src="${ctx}/img/login/icon2.png"/></i>
                  <input id="cxPassword" type="password" name="passWord" placeholder="请输入密码" tabindex="1">
                </div>
                <div class="textbox hide">
                            <div class="code">
                              <i><img src="${ctx}/img/login/icon3.png"/></i>
                              <input type="text" name="username" placeholder="验证码">
                              <div class="codeimg" >
                                 <img src="${ctx}/img/login/code.png" />
                                 <i class="layui-icon layui-icon-refresh"></i>
                              </div>
                            </div>
                          </div>

                <button class="loginbtn" type="submit">登录</button>
              </div>
          </form>
              <div id="errorCx" class="error hide">
                <div class="text"></div>
              </div>
       </div>
       <div id="boxJd" class="dialog">
              <div class="text">
                <div class="textbox">
                  <i class="name"><img src="${ctx}/img/login/icon1.png"/></i>
                  <input id="jdUsername" type="text" name="username" placeholder="请输入用户名">
                </div>
                <div class="textbox">
                  <i class="psw"><img src="${ctx}/img/login/icon2.png"/></i>
                  <input id="jdPassword" type="password" name="password" placeholder="请输入密码">
                </div>

                <button class="loginbtn" type="button">登录</button>
              </div>
              <div id="errorJd" class="error hide">
                <div class="text"></div>
              </div>
       </div>
       <div id="boxGl" class="dialog">
         <form id="glForm" name="form" method="post" action="${ctx}/admin/adminuserlogin.action?action=login" >
              <div class="text">
                <div class="textbox">
                  <i class="name"><img src="${ctx}/img/login/icon1.png"/></i>
                  <input id="glUsername" type="text" name="username" placeholder="请输入用户名">
                </div>
                <div class="textbox">
                  <i class="psw"><img src="${ctx}/img/login/icon2.png"/></i>
                  <input id="glPassword" type="password" name="password" placeholder="请输入密码">
                </div>
                <button class="loginbtn" type="submit">登录</button>
              </div>
         </form>
              <div id="errorGl" class="error hide">
                <div class="text"></div>
              </div>
       </div>
    </div>
  </div> 
  <script src="${ctx}/js/jquery-1.11.2.min.js"></script>
  <script src="${ctx}/layui/layui.all.js"></script>
  <script type="text/javascript">
  var label = window.localStorage.getItem('label');
          if(!label||label===''){
              if("adminLogin"==="${action}"){
                label = "Gl";
              }else{
                label = "Cx";
              }

          }
    $(document).ready(function(){

        var tip = '<ww:property value="tipInfo" />';
        if(tip!=null&&tip!=''){
            console.log(tip);
            $("#error"+label+" .text").html(tip);
            $("#error"+label).show();
        }
        $('#cxForm').submit(function () {
              var name = $.trim($('#cxUsername').val());
              // Check if empty of not
              if (name  === '') {
                  $("#errorCx .text").text("用户名不能为空");
                  $("#errorCx").show();
                  return false;
              }
               var pass = $.trim($('#cxPassword').val());
              if (pass  === '') {
                  $("#errorCx .text").text("密码不能为空");
                  $("#errorCx").show();
                  return false;
              }
        });
        $('#glForm').submit(function () {
                      var name = $.trim($('#glUsername').val());
                      // Check if empty of not
                      if (name  === '') {
                          $("#errorGl .text").text("用户名不能为空");
                          $("#errorGl").show();
                          return false;
                      }
                       var pass = $.trim($('#glPassword').val());
                      if (pass  === '') {
                          $("#errorGl .text").text("密码不能为空");
                          $("#errorGl").show();
                          return false;
                      }
                });

        $('.layui-nav-item').on('click',function () {
          var id=$(this).data('id');
          $('.dialog').removeClass('active');
          $('#box'+id).addClass('active');
          $('.layui-nav-item').removeClass('layui-this');
          $('#li'+id).addClass('layui-this');
          label = id;
          window.localStorage.setItem('label',label);
        }).filter("[data-id='"+label+"']").click();


        //var selectedForm = $("#loginArea")
        $("#boxJd .loginbtn").on("click",function(){
            loginToJd();
        });
    });

    function readCert() {
        	clearForm();

        	//CertCtl.ReadCardCallBack = calltest;

                    	var ret = CertCtl.readCert();

                    	ret = JStrToObj(ret);
                    	if (ret.resultFlag==-1){
                    		//DisplayInfo(ret);
                            $("#error"+label+" .text").html("未读到卡");
                            $("#error"+label).show();
                    	}else{
                    		//var userName = document.getElementById("userName");
                    		//userName.value = ret.resultContent.certNumber;
                    		$("#error"+label+" .text").html("");
                            $("#error"+label).hide();
                            $("#cxUsername").val(ret.resultContent.certNumber);
                    	}


        }

        function JStrToObj(str){
        	return eval("(" + str + ")");
        }

        function calltest(result)
        {
        alert("fff");
        	clearForm();


        	var ret = JStrToObj(result);
        	if (ret.resultFlag==-1){
        		$("#error"+label+" .text").html("未读到卡");
        	}else{
        		$("#divTips").html();
        		$("#userName").val(ret.resultContent.certNumber);
        	}
        }

        function clearForm(){
            $("#error"+label+" .text").html();
            $("#cxUsername").val();
        }

    function loginToJd(){
        var user = $("#jdUsername").val();
        var pass = $("#jdPassword").val();

        <c:set var="dzdaLoginUrl" value="<%=com.hele.sts.helper.Config.DZDA_ADDR%>" />

        var form =$("<form id='jdForm' action='${dzdaLoginUrl}' method='post'>" +
                "<input type='hidden' name='username' value=''/> " +
                "<input type='hidden' name='password' value=''/> " +
                "</form> ");
         $( "body").append(form);
         $("#jdForm input[name='username']").val(user);
         $("#jdForm input[name='password']").val(pass);

         //form.submit();
         document.getElementById("jdForm").submit();
        //$( "#SMAL" ).remove();//清空节点
        //$( "body").append("<div id='SMAL' name='SMAL' style='display: none'></div>");//载入iframe
        //(function(){
        //    $( "#SMAL" ).contents().find('body').html(form);//将form表单塞入iframe;
        //    $( "#SMAL" ).contents().find("form input[name='username']").val(user);
        //    $( "#SMAL" ).contents().find("form input[name='password']").val(pass);
        //    $( "#SMAL" ).contents().find('form').submit();
        //}());
    }
  </script>
  </body>
</html>